/**
 * 将所有接口统一起来便于维护
 * @file
 * @author mano233
 * @date 2019-03-25
 */
import {instance, CancelTokenFn} from './instance';
import formAPI from './model/formAPI';
import userAPI from './model/userAPI';
/**
 * 分页加载事件
 * @param {*} params 要提交的参数
 * @return {Promise<any>}
 */
const getEvent = (params) => {
    return instance({
        url: '/event',
        method: 'get',
        data: params,
    });
};

const getAdminEvent = ()=>{
    return instance({
        url: '/event/admin',
        method: 'get',
    });
};

const getEventById = (eventId) => {
    return instance({
        url: '/event/' + eventId,
        method: 'get',
    });
};

const getEventForm = (eventId, type) =>{
    return instance({
        url: `/event/${eventId}/form?type=${type}`,
        method: 'get',
    });
};

const accessForm = (formId)=>{
    return instance({
        url: `/form/access?formId=${formId}`,
        method: 'put',
    });
};

const upload = (data) => {
    return instance({
        url: '/upload',
        method: 'post',
        data,
    });
};
const addEvent = () => {
    return instance({
        url: '/event',
        method: 'post',
    });
};
const updateEvent =(data)=>{
    return instance({
        url: '/event/',
        method: 'put',
        data,
    });
};
const login = (data) => {
    return instance({
        url: '/login',
        method: 'post',
        data,
    });
};

const saveEvent = (data) => {
    return instance({
        url: '/event',
        method: 'post',
        data,
    });
};

export default {
    getEvent,
    addEvent,
    updateEvent,
    getEventForm,
    getEventById,
    accessForm,
    saveEvent,
    getAdminEvent,
    upload,
    formAPI,
    userAPI,
    CancelTokenFn,
    login,
};
